﻿using System;
using System.Data;
using CoreLab.Oracle; //using Devart.Data.Oracle; //using Oracle.DataAccess.Client;
using System.Web;
using System.Web.Caching;


using LMD.Constant;
using LMD.Lib.Oracle;

namespace Cached
{
    /// <summary>
    /// Summary description for FeedBlocking
    /// </summary>
    public class FeedBlocking : CacheAbstraction
    {
        public DataTable GetUserFeedBlockingList(String sxUserId)
        {
            return GetUserFeedBlockingList(sxUserId, false);
        }
        public DataTable GetUserFeedBlockingList(String sxUserId, bool bForceRefresh)
        {
            String sxCacheKey = KCache.FEED_BLOCKING_USER + sxUserId;

            if(bForceRefresh)
            {
                HttpRuntime.Cache.Remove(sxCacheKey);
            }

            if (HttpRuntime.Cache[sxCacheKey] == null)
            {
                DBLib dbl = new DBLib();

                OracleParameter param = new OracleParameter();
                param.ParameterName = "prmID";
                param.OracleDbType = OracleDbType.VarChar;
                param.Value = sxUserId;

                String sxQuery =
                    @"
                    select 
                        t1.BLOCKED_USER_ID ID, 
                        v1.EMPLOYEE_NAME NAME
                    from 
                        T_BLOCK_USER t1
                        left join V_ICP_USER v1
                            on t1.BLOCKED_USER_ID = v1.ICP_USER_ID
                    where 
                        t1.ICP_USER_ID = :prmID    
                    order by
                        v1.EMPLOYEE_NAME asc
                    ";

                DataTable dt = dbl.GetDataTable(sxQuery, param);

                AddToCache(sxCacheKey, dt, CacheType.Daily);
                
            }
            return (DataTable)HttpRuntime.Cache[sxCacheKey];
        }

        public DataTable GetCustomerFeedBlockingList(String sxUserId)
        {
            return GetCustomerFeedBlockingList(sxUserId, false);
        }
        public DataTable GetCustomerFeedBlockingList(String sxUserId, bool bForceRefresh)
        {
            String sxCacheKey = KCache.FEED_BLOCKING_CUSTOMER + sxUserId;

            if (bForceRefresh)
            {
                HttpRuntime.Cache.Remove(sxCacheKey);
            }

            if (HttpRuntime.Cache[sxCacheKey] == null)
            {
                DBLib dbl = new DBLib();

                OracleParameter param = new OracleParameter();
                param.ParameterName = "prmID";
                param.OracleDbType = OracleDbType.VarChar;
                param.Value = sxUserId;

                String sxQuery =
                    @"
                    select 
                        t1.CUSTOMER_ID ID, 
                        v1.COMPANY_NAME NAME
                    from 
                        T_BLOCK_CUSTOMER t1
                        left join V_ICP_CUSTOMER v1
                            on t1.CUSTOMER_ID = v1.CUSTOMER_ID
                    where 
                        t1.ICP_USER_ID = :prmID    
                    order by
                        v1.COMPANY_NAME asc
                    ";

                DataTable dt = dbl.GetDataTable(sxQuery, param);

                AddToCache(sxCacheKey, dt, CacheType.Daily);

            }
            return (DataTable)HttpRuntime.Cache[sxCacheKey];
        }

        public override String GetCacheFilename()
        {
            return KCache.Filename.FEED_BLOCKING;
        }
    }
}